package cn.lg.soar.flow.api.model;

import cn.lg.soar.flow.api.utils.ProcessUtils;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

/**
 * @author luguoxiang
 * @date 2023/6/27
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
@Getter
@Setter
public class BaseAuditDTO {

    /**
     * 当前表单数据
     */
    @Schema(description = "表单数据")
    private Map<String, Object> variables;

    /**
     * 审批意见
     */
    @Schema(description = "审批意见")
    private String comments;

    /**
     * 自选审批人
     */
    @Schema(description = "自选审批人")
    private Map<String, Collection<String>> approvers;

    public void putUserApprover(String nodeKey, Collection<Long> userIds) {
        if (approvers == null) {
            approvers = new HashMap<>();
        }
        approvers.put(nodeKey, userIds.stream().map(ProcessUtils::toUserApproval).toList());
    }

    public void putPostApprover(String nodeKey, Collection<Long> postIds) {
        if (approvers == null) {
            approvers = new HashMap<>();
        }
        approvers.put(nodeKey, postIds.stream().map(ProcessUtils::toPostApproval).toList());
    }

}
